package org.wdcode.back.dao.hibernate;

import org.wdcode.base.interfaces.dao.impl.BaseDaoHibernateHelper;
import org.wdcode.back.dao.UserDao;
import org.wdcode.back.helper.UserHelper;
import org.wdcode.back.po.User;

/**
 * 用户管理Dao实现
 * @author WD
 * @since JDK6
 * @version 1.0 2009-11-23
 */
public final class UserDaoImpl extends BaseDaoHibernateHelper<User, UserHelper> implements UserDao {
	// 更新密码命名SQL
	private final static String	UPDATE_PWD	= "updatePwd";
	// 重置密码命名SQL
	private final static String	RESET_PWD	= "resetPwd";

	/**
	 * 修改密码
	 * @param user 用户实体
	 * @param oldPwd 原密码
	 */
	public boolean updatePwd(User user, String oldPwd) {
		return getHibernateDao().executeByNamed(UPDATE_PWD, user.getPassword(), user.getId(), oldPwd) > 0 ? true : false;
	}

	/**
	 * 重置密码
	 * @param user 用户实体
	 * @return 是否成功
	 */
	public boolean resetPwd(User user) {
		return getHibernateDao().executeByNamed(RESET_PWD, user.getPassword(), user.getId()) > 0 ? true : false;
	}
}
